<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:thSys="">
<div th:replace="admin/module/macros :: head('分类管理')"></div>
<body class="app sidebar-mini rtl">
	<main class="app-content">
	<div th:replace="admin/module/macros :: header"></div>
	<div th:replace="admin/module/macros :: sidebar"></div>
	<div class="app-title">
		<div>
			<h1>分类目录</h1>
		</div>
		<ul class="app-breadcrumb breadcrumb">
			<li class="breadcrumb-item"><i class="fa fa-home fa-lg"></i></li>
			<li class="breadcrumb-item"><a href="/admin/category">分类目录</a></li>
		</ul>
	</div>
	<div class="row">
		<div class="col-md-12">
			<div class="tile">
				<div class="row">
					<div class="col-lg-5">
						<th:block th:if="${category} == null ">
							<h4 class="tile-title">添加分类</h4>
						</th:block>
						<th:block th:if="${category} != null">
							<h4 class="tile-title">修改分类</h4>
						</th:block>
						<form action="/admin/category/save" method="post"
							autocomplete="off">
							<input type="hidden" name="categoryId" id="categoryid"
								th:value="${category!=null ? category.categoryId :''}">
							<div class="form-group">
								<label class="col-form-label" for="inputDefault">*名称</label> <input
									class="form-control" id="inputDefault"
									th:value="${category != null ? category.categoryName : ''}"
									name="categoryName" type="text">
							</div>
							<div class="form-group">
								<label class="col-form-label" for="inputDefault">*路径名称</label> <input
									class="form-control" id="inputDefault"
									th:value="${category != null ? category.categoryUrl : ''}"
									type="text" name="categoryUrl">
							</div>
							<div class="form-group">
								<label class="col-form-label">描述<span
									data-toggle="tooltip" data-placement="top" title="分类描述"
									style="cursor: pointer"> <i
										class="fa fa-question-circle" aria-hidden="true"></i>
								</span></label>
								<textarea class="form-control" rows="3" id=""
									th:text="${category != null ? category.categoryDescribe : ''}"
									th:value="${category != null ? category.categoryDescribe : ''}"
									name="categoryDescribe" style="resize: none"></textarea>
							</div>
							<div class="tile-footer">
								<button class="btn btn-sm btn-outline-primary" type="submit">保存分类</button>
								<th:block th:if="${category} != null">
									<a class="btn btn-sm btn-outline-info" href="/admin/category">返回添加</a>
								</th:block>
							</div>
						</form>
					</div>
					<div class="col-lg-7">
						<h4 class="tile-title">所有分类</h4>
						<div class="table-responsive">
							<table class="table">
								<thead>
									<tr>
										<th>分类名称</th>
										<th>分类路径</th>
										<th>分类描述</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
									<tr th:each="category : ${Categorys}">
										<td th:text="${category.categoryName}"></td>
										<td th:text="${category.categoryUrl}"></td>
										<td th:text="${category.categoryDescribe}"></td>
										<td><a class="btn btn-sm btn-outline-primary"
											th:href="@{/admin/category/edit(categoryId=${category.categoryId})}">修改</a>
											<button class="btn btn-sm btn-outline-danger"
												th:onclick="'javascript:showModel('+${category.categoryId}+')'">删除</button>
										</td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>
				</div>

			</div>
		</div>
	</div>
	</main>
	<!-- 删除确认弹出层 -->
	<div th:replace="admin/module/macros :: remove"></div>
	<div th:replace="admin/module/macros :: comm"></div>
	<div th:replace="admin/module/macros :: bootstrapValidator"></div>
	<script type="text/javascript">
	$(function(){
		$("form").bootstrapValidator({
			message: 'This value is not valid',
           　		feedbackIcons: {
               　　　　　　　　valid: 'glyphicon glyphicon-ok',
               　　　　　　　　invalid: 'glyphicon glyphicon-remove',
               　　　　　　　　validating: 'glyphicon glyphicon-refresh'
           　　　　　　　　   },
            fields: {
            	categoryName: {
                   message: '名称验证失败',
                   validators: {
                       notEmpty: {
                           message: '名称不能为空'
                       }
                   }
               },
               categoryUrl: {
            	   message: '路径名称验证失败',
                   validators: {
                       notEmpty: {
                           message: '路径名称不能为空'
                       }
                   }
               }
           }
		});
	});
		function showModel(categoryId) {
			$("#categoryid").val(categoryId);
			$("#removeModal").modal();
		}
		function remove() {
			window.location.href = "/admin/category/remove?categoryId="
					+ $("#categoryid").val();
		}
	</script>
</body>
</html>